package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.entity.Dept;
import com.woniu.entity.DeptExample;
import com.woniu.mapper.DeptMapper;
import com.woniu.service.DeptService;
import com.woniu.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 16327
 * @date: 2020/12/26 10:52
 * @description:
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    DeptMapper deptMapper;
    @Override
    public List<DeptVo> findAllDept(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<DeptVo> deptVos = deptMapper.selectDeptVoAll();
        return deptVos;
    }
    @Override
    public int  delDept(Integer deptid){
        int i= deptMapper.deleteByPrimaryKey(deptid);
        return i;
    }

    @Override
    public DeptVo selectByDeptid(Integer deptid) {
        DeptVo deptVo = deptMapper.selectByPrimaryKey(deptid);
        return deptVo;
    }

    @Override
    public int updateDept(Dept dept) {
        int i = deptMapper.updateByPrimaryKeySelective(dept);
        return i;
    }

    @Override
    public List<DeptVo> selectDeptByLike(Dept dept) {
        DeptExample exampel=new DeptExample();
        exampel.createCriteria().andDeptnameLike(dept.getDeptname());
        List<DeptVo> depts = deptMapper.selectByExample(exampel);
        return depts;
    }

    @Override
    public int insertDept(Dept dept) {
        int i = deptMapper.insert(dept);
        return i;
    }

    @Override
    public int updateDept2(Dept dept1,Dept dept2) {
        int i = deptMapper.updateByPrimaryKeySelective(dept1);
        int a=1/0;
        int j = deptMapper.updateByPrimaryKeySelective(dept2);
        return i+j;
    }
}
